/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import Entity.CTBaoCaoTonKho;
import Util.DatabaseHandle;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Dark_Knight
 */
public class CTBaoCaoTonKhoImpl implements CTBaoCaoTonKhoDAO{

    public boolean add(CTBaoCaoTonKho data) {
        String sql = "{ call sp_CT_BAOCAOTONKHO_add(?,?,?,?,?,?) }";
        DatabaseHandle db = new DatabaseHandle(sql, true);
        
        try {
            db.setParameter(1, data.getMaCTBCTK());
            db.setParameter(2, data.getMaBaoCaoTon());
            db.setParameter(3, data.getMaSach());
            db.setParameter(4, data.getTonDau());
            db.setParameter(5, data.getPhatSinh());
            db.setParameter(6, data.getTonCuoi());
            
            db.executeStorePro();
            db.closed();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(CTBaoCaoTonKhoImpl.class.getName()).log(Level.SEVERE, null, ex);
            db.closed();
            return false;
        }
        
    } 

    public boolean delete(int MaCTBCTK) {
        String sql = "{ call sp_CT_BAOCAOTONKHO_delete(?) }";
        DatabaseHandle db = new DatabaseHandle(sql, true);
        
        try {
            db.setParameter(1, MaCTBCTK);
            db.executeStorePro();
            db.closed();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(CTBaoCaoTonKhoImpl.class.getName()).log(Level.SEVERE, null, ex);
            db.closed();
            return false;
        }
    }

    public boolean edit(CTBaoCaoTonKho data) {
        String sql = "{ call sp_CT_BAOCAOTONKHO_edit(?,?,?,?,?,?) }";
        DatabaseHandle db = new DatabaseHandle(sql, true);
        
        try {
            db.setParameter(1, data.getMaCTBCTK());
            db.setParameter(2, data.getMaBaoCaoTon());
            db.setParameter(3, data.getMaSach());
            db.setParameter(4, data.getTonDau());
            db.setParameter(5, data.getPhatSinh());
            db.setParameter(6, data.getTonCuoi());
            
            db.executeStorePro();
            db.closed();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(CTBaoCaoTonKhoImpl.class.getName()).log(Level.SEVERE, null, ex);
            db.closed();
            return false;
        }
    }
    
}
